package com.shuang.tree35;

public class MergeTrees {

    //递归 前序
    public TreeNode mergeTrees(TreeNode root1, TreeNode root2) {

        //终止条件
        if (root1 == null){
            return root2; //root1为空合并后 返回的就是root2
        }

        if (root2 == null){
            return root1;
        }

        //最后合并后将root1作为最后合并修改后的树返回
        //中
        root1.val += root2.val;
        //左
        root1.left = mergeTrees(root1.left, root2.left);
        //右
        root1.right = mergeTrees(root1.right, root2.right);

        return root1;
    }
}
